# 强力修复所有Java文件的编码问题

$javaFiles = Get-ChildItem -Path "src\main\java" -Filter "*.java" -Recurse
$count = 0

foreach ($file in $javaFiles) {
    try {
        # 读取文件内容，自动检测编码
        $content = Get-Content $file.FullName -Raw
        
        # 如果内容为空或null，跳过
        if ([string]::IsNullOrWhiteSpace($content)) {
            continue
        }
        
        # 移除BOM字符（如果存在）
        if ($content.StartsWith([char]0xFEFF)) {
            $content = $content.Substring(1)
        }
        
        # 重新写入文件，使用UTF-8无BOM编码
        [System.IO.File]::WriteAllText($file.FullName, $content, [System.Text.UTF8Encoding]::new($false))
        
        $count++
        if ($count % 20 -eq 0) {
            Write-Host "Fixed $count files..."
        }
    }
    catch {
        Write-Host "Error processing file: $($file.Name) - $($_.Exception.Message)"
    }
}

Write-Host "Fixed $count files total. Encoding issues resolved!"